package com.xingshang.controller;

import com.xingshang.model.po.Category;
import com.xingshang.model.po.Goods;
import com.xingshang.service.CategoryService;
import com.xingshang.service.GoodsService;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("goods")
@RequiredArgsConstructor
public class GoodsController {

    private final GoodsService goodsService;
    private final CategoryService categoryService;
    @GetMapping("{id}")
    public String goods(Model model, HttpSession session, @PathVariable Integer id) {
        Goods goods = goodsService.getById(id);
        List<Category> categories = categoryService.list();
        model.addAttribute("goods", goods);
        model.addAttribute("categories", categories);
        return "goods_view";
    }
}
